// JavaScript Document
$(function(){
	$("#myli").mouseover(function(){
		$("#myspan").css("display","block");
		$("#current_userInfo").css("display","block");
	});
	
	$("#myli").mouseout(function(){
		$("#myspan").css("display","none");
		$("#current_userInfo").css("display","none");
	});
})

/*字符计算*/
var total_num=400;
function getNum(){
	var current_num=$("#word").val();
	var remain_num=parseInt(total_num-current_num.length);
	$("#max_words").text(remain_num);
}

/*发表时的验证码*/
function changeCode() {
	$("#safecodeloginimg").attr("src","valiCodeImg.jsp?t="+new Date());
}

/*发表心情*/
function publishMood(){
	var mname=$.trim($("#id_title").val());
	var mtag;
	var mcontent=$.trim($("#word").val());
	var mstatus=document.getElementById("check").checked;
	var mtime=currentTime();
	var code = $.trim($("#verifycode").val());
	
	var tags=document.getElementsByName("chice");
	for(var i=0; i < tags.length; i++){
		if(tags[i].checked==true){
			mtag=tags[i].value;
		}
	}
	
	if(mstatus==true){
		mstatus="匿名";
	}else{
		mstatus=uname;
	}
	
	if(mname==null || mname==""){
		alert("标题不能为空!");
		return;
	}
	
	if(mtag==null || mtag=="") {
		alert("请选择标签!");
		return;
	}
	
	if(code == "" || code==null) { 
		alert("验证码不能为空!");
		return;
	}
	
	if(!checkInfo(mname) || !checkInfo(mcontent)) {
		alert("非法输入!");
	} else {
		$.post("../json/moodsAction_addOneMood",{
			"mood.w_uid":w_uid,
			"mood.mname":mname,
			"mood.mtag":mtag,
			"mood.mcontent":mcontent,
			"mood.mstatus":mstatus,
			"mood.mtime":mtime,
			code:code
		},function(data){
			data=parseInt($.trim(data.result));
			if(data==1){
				alert("验证码错误!");
				changeCode();
				$("#verifycode").select();
			}else if(data==2){
				alert("发表成功!");
				location.href="moods.jsp";
			}else{
				alert("系统错误，请稍后再试!");
			}
		});
	}
}

/*当前时间*/
function currentTime(){
	var d=new Date();
	var h=d.getHours().toString();
	var m=d.getMinutes().toString();
	if(h.length<2){
		h="0"+h;
	}
	if(m.length<2){
		m="0"+m;
	}
	var time=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()+" "+h+":"+m;
	return time;
}

function checkInfo(s) { 
	var result= s.replace(/<script.*?>.*?<\/script>/ig, ''); 
	if(result == ""){
		return false;
	}
	return true;
}
